
#include "movables.h"


Movables::Movables()
{
}


Movables::Movables(Movable_type object_type, int x_loc, int y_loc):
									_type(object_type), 
									_x(x_loc), _y(y_loc), 
									_direction(RIGHT), 
									//_bitmap(Bitmaps::object_bitmap(object_type)), 
									//_bitmap(Bitmaps::get_default_bitmap(object_type)),
									_radius(1),
									_is_ghost(false)
									
{
	switch (_type)
	{
		case DIGDUG:  _speed = 1; break;
		case MONSTER: _speed = 1; break;
		case PROJECTILE: _speed = 1; break; 
	}

	vector< vector<int> >::iterator start_it = _monster_route.begin();
	vector< vector<int> >::iterator end_it = _monster_route.end();

	_monster_route.erase(start_it, end_it);
	
}

void Movables::set_location(int new_x_loc, int new_y_loc)
{
	_x = new_x_loc;
	_y = new_y_loc;
}


void Movables::set_direction(Direction new_dir)
{
	_direction = new_dir;
}


void Movables::set_status(Status new_status)
{
	_status = new_status;
}


int Movables::x()
{
	return _x;
}
int Movables::y()
{
	return _y;
}

int Movables::radius()
{
	return _radius;
}

Direction Movables::direction()
{
//convert from enumerated type Direction to int
	return _direction;
}
	
int Movables::speed()
{
	return _speed;
}

bool Movables::status()
{
	//convert from enumerated type Status which is either 0 or 1 to type bool
	return static_cast<bool>(_status);  
}

Movable_type Movables::type()
{
//convert from enumerated type Object_type to int
	return _type;
}

ALLEGRO_BITMAP *Movables::bitmap()
{
	return _bitmap;
}

void Movables::set_route(vector< vector<int> > co_ordinates)
{
	//if(_monster_route.empty() || _monster_route.at(0).size() > co_ordinates.at(0).size())
	//{
		_monster_route = co_ordinates;
		cout<<"A new route has been set"<<endl;
	//}
}

vector<int> Movables::get_next_coordinate()
{
	vector<int> co_ordinate = vector<int> (2); 
	if(!_monster_route.empty())
	{
		//obtain the x and y co_ordinates from the next position along the route which the monster should follow
			
			_monster_route.at(0).pop_back();
			_monster_route.at(1).pop_back();
			co_ordinate.at(0) = _monster_route.at(0).back();
			co_ordinate.at(1) = _monster_route.at(1).back();

	}
	
	//if the monster cannot reach digdug, then stay still
	else 
	{
		co_ordinate.at(0) = _x;
		co_ordinate.at(1) = _y;
	}	
	
	return co_ordinate;
}

Direction Movables::get_monster_move_direction()
{
	vector <int> next_co_ord = get_next_coordinate();
	int new_x = next_co_ord.at(0);
	int new_y = next_co_ord.at(1);

	cout<<"new_x = "<<new_x<<" _ " <<_x<<" = x"<<endl;
	cout<<"new_y = "<<new_y<<" _ " <<_y<<" = y"<<endl;
	if(new_y < _y) return UP;
	else if(new_y > _y) return DOWN;
	else if(new_x < _x) return LEFT;
	else return RIGHT;	

}

bool Movables::is_ghost()
{
	return _is_ghost;
}

void Movables::is_ghost(bool set)
{
	_is_ghost  = set; 
}